package com.sy.core.web.hr;

import com.sy.core.model.HrStaff;
import com.sy.core.service.HrStaffService;
import com.sy.core.util.RestResult;
import com.sy.core.web.BaseCtl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;




/**
 * 	TODO 请用一句话描述该类的作用
 * @version 1.0
 * @since 1.0
 */

@Controller
@RequestMapping("/hrStaff")
public class HrStaffCtl extends BaseCtl {

    @Autowired
    private HrStaffService  hrStaffService;
    

	@RequestMapping("/{path}")
	public ModelAndView toAnyPage(@PathVariable String path,ModelAndView mv){
	    mv.setViewName(path);
	    return mv;
    }
    
    /**
     * Action for Add
     */
    @RequestMapping(value = "/save",produces = "application/json;charset=utf-8")
    @ResponseBody
    public RestResult save(HrStaff hrStaff){
        RestResult rr = null;
        try {
            hrStaffService.insert(hrStaff);
            rr=new RestResult("200","SUCCESS");
        } catch (Exception e) {
            e.printStackTrace();
            rr = new RestResult("201","FAILED");
        }
        return rr;
    }

    /**
     * Action for update
     */
    @RequestMapping(value = "/update",produces = "application/json;charset=utf-8")
    @ResponseBody
    public RestResult update(HrStaff hrStaff){
        RestResult rr = null;
        try {
        hrStaffService.update(hrStaff);
        rr=new RestResult("200","SUCCESS");
        } catch (Exception e) {
        e.printStackTrace();
        rr = new RestResult("201","FAILED");
        }
        return rr;
    }
    
    /**
     * Action for SelectOneByKey
     */
    @RequestMapping(value = "/query/{key}",produces = "application/json;charset=utf-8")
    @ResponseBody
    public RestResult queryByPrimaryKey(@PathVariable String key){
       try{
            HrStaff hrStaff = hrStaffService.queryByPrimaryKey(key);
      	 	return new RestResult("200","SUCCESS",hrStaff);
       }catch(Exception e){
    	   	logger.error("Query Model HrStaff By PrimaryKey Is Fail:"+e.getMessage());
       }
       		return new RestResult("201","FAIL");
    }
    
    /**
     * Action for SelectList
     */
    @RequestMapping(value = "/list",produces = "application/json;charset=utf-8")
    @ResponseBody
    public RestResult queryList(HrStaff hrStaff){
       try{
      		List<HrStaff> hrStaffList = hrStaffService.queryByCondition(hrStaff);
      	 	return new RestResult("200","SUCCESS",hrStaffList);
       }catch(Exception e){
    	   logger.error("Query Model HrStaff List Fail :"+e.getMessage());
    	   return new RestResult("201","FAIL");
       }
    }
    
    /**
     * Action for DeleteModel
     */
    @RequestMapping("/delete")
    @ResponseBody
    public RestResult delete(String pks){
        RestResult rr = null;
        try {
        hrStaffService.delete(pks);
        rr=new RestResult("200","SUCCESS");
        } catch (Exception e) {
        e.printStackTrace();
        rr = new RestResult("201","FAILED");
        }
        return rr;
    }

   
}
